//TODO: License Header.

/*
This code is licensed under the BSD license.

*/
package analysis.metrics

import primitives.cluster.ClusterHead
import primitives.graph.Node
import search.util.TreeLoader2
import static Math.min
import primitives.cluster.*;
import primitives.graph.*;
import search.fitnessfunctions.TreeFitnessFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
import search.fitnessfunctions.*;
class FitnessFunctionMetric{

	static double evaluate(ClusterHead tree){
		

	
        return tree.children.size()
        
	}
	
	public FitnessFunctionMetric(filename, ffname){

		ClusterHead tree = TreeLoader2.loadTreeFromSerial(new File(filename))
		Class<?> ffClass = Object.class;

		    try {
		        ffClass = Class.forName(ffname, true, this.getClass().getClassLoader());
    
		    } catch (ClassNotFoundException ex) {
		        Logger.getLogger(FitnessFunctionMetric.class.getName()).log(Level.SEVERE, "Failed to load fitness function " + ffname, ex);
		    } //TODO: add support for Bunch adapted FFs (these require constructors)
		    TreeFitnessFunction fitnessFunction = null;
		    try {
		        fitnessFunction = (TreeFitnessFunction) ffClass.newInstance();
		    } catch (InstantiationException ex) {
		        Logger.getLogger(FitnessFunctionMetric.class.getName()).log(Level.SEVERE, "Failed to instantiate fitness function " + ffname, ex);
		    } catch (IllegalAccessException ex) {
		        Logger.getLogger(FitnessFunctionMetric.class.getName()).log(Level.SEVERE, "IllegalAccessException when instantiating " + ffname, ex);
		    }
		
		fitnessFunction.setTree(tree);
		print fitnessFunction.evaluate(tree);
		
	}
	public static void main(String[] args){
		new FitnessFunctionMetric(args[0],args[1])
		
	}
	
}